﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    mc:Ignorable="d">
	<!-- Resource dictionary entries should be defined here. -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Colors.xaml"/>
        <ResourceDictionary Source="ScrollViewerStyle.xaml"/>
        <ResourceDictionary Source="ListBoxItemStyle.xaml"/>
        <ResourceDictionary Source="ValidationToolTipTemplate.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type ListBox}">
        <Setter Property="Foreground">
            <Setter.Value>
                <SolidColorBrush Color="{StaticResource Application_ListBox_Foreground}"/>
            </Setter.Value>
        </Setter>
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="true" />
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=ListBoxTemplate, TypeInTargetAssembly={x:Type ListBox}}}"/>
		<Setter Property="ItemContainerStyle" Value="{DynamicResource ListBoxItemStyle}"/>
    </Style>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=ListBoxTemplate, TypeInTargetAssembly={x:Type ListBox}}" TargetType="ListBox">
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="ValidationStates">
                    <VisualState x:Name="Valid">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="InvalidFocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToolTip.IsOpen)" Storyboard.TargetName="validationTooltip">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <sys:Boolean>true</sys:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="InvalidUnfocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border Name="Border" BorderThickness="1">
                <Border.Background>
                    <SolidColorBrush Color="{StaticResource Application_ListBox_Background}" />
                </Border.Background>
                <Border.BorderBrush>
                    <SolidColorBrush Color="{StaticResource Application_ListBox_BorderBrush}" />
                </Border.BorderBrush>
                <ScrollViewer Margin="0" Focusable="false">
                    <StackPanel Margin="2" IsItemsHost="True" />
                </ScrollViewer>
            </Border>
            <Border x:Name="ValidationErrorElement" BorderThickness="1" Margin="0" CornerRadius="2" Visibility="Collapsed" IsHitTestVisible="True">
                <Border.BorderBrush>
                    <SolidColorBrush Color="{StaticResource Application_ComboBox_BorderBrush_ValidationError}"/>
                </Border.BorderBrush>
                <ToolTipService.ToolTip>
                    <ToolTip x:Name="validationTooltip" Placement="Bottom"
    					    Template="{DynamicResource ValidationToolTipTemplate}"
    					    PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
    					    DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"/>
                </ToolTipService.ToolTip>
            </Border>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

</ResourceDictionary>